//
//  NYExaminationCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/10.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYExaminationCell.h"

@interface NYExaminationCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *lineImgView;

@end

@implementation NYExaminationCell

//MARK :Nimbus
- (BOOL)shouldUpdateCellWithObject:(NYExaminationModel *)object atIndexPath:(NSIndexPath *)indexPath{
        
    if (![object isKindOfClass:[NYExaminationModel class]]) {
            return false;
    }
    self.indexPath = indexPath;
    [self updateContentWithModel:object];
    return true;
}
+ (CGFloat)heightForObject:(id)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView {
        
    return 45.f;
}
- (void)setupView {
    [super setupView];
    //布局
    self.accessoryType = UITableViewCellAccessoryNone;
    
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.lineImgView];

    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
            make.top.bottom.equalTo(self.contentView);
            make.left.equalTo(self.contentView).offset(15);
            make.right.equalTo(self.contentView).offset(-15);
    }];
    [self.lineImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(1);
    }];

}
- (void)updateContent {
        [super updateContent];
}

#pragma mark - Private Method
- (void)updateContentWithModel:(NYExaminationModel *)model {
        
    self.titleLabel.text = [NSString stringWithFormat:@"%ld、%@",self.indexPath.row + 1, model.examination_title];
}

#pragma mark - Setter Getter Methods
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _titleLabel.font = UIFontBoldMake(14.f);
        _titleLabel.textColor = UIColorMakeWithHex(@"#666666");
    }
    return _titleLabel;
}
- (UIImageView *)lineImgView {
    if (!_lineImgView) {
        _lineImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 15, 1)];
        //画一条虚线
        UIGraphicsBeginImageContext(_lineImgView.frame.size);   //开始画线
        [_lineImgView.image drawInRect:CGRectMake(0, 0, CGRectGetWidth(_lineImgView.frame), CGRectGetHeight(_lineImgView.frame))];
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  //设置线条终点形状
        const CGFloat lengths[] = {2,2};
        CGContextRef line = UIGraphicsGetCurrentContext();
        CGContextSetStrokeColorWithColor(line, [UIColor lightGrayColor].CGColor);
        CGContextSetLineDash(line, 0, lengths, 1);  //画虚线
        CGContextMoveToPoint(line, 0.0, 0.0);    //开始画线
        CGContextAddLineToPoint(line, _lineImgView.bounds.size.width, 0.0);
        CGContextStrokePath(line);
        _lineImgView.image = UIGraphicsGetImageFromCurrentImageContext();
    }
    return _lineImgView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
